<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="a"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="static/layui/css/layui.css" media="all">
</head>
<body>
	<form class="layui-form" action="" style="margin-top: 60px;">
		<input type="hidden" name="studentId" value="${stu.studentId}"
			class="layui-input">
		<div class="layui-form-item layui-inline">
			<label class="layui-form-label">姓名</label>
			<div class="layui-input-block">
				<input type="text" name="studentName" value="${stu.studentName}"
					lay-verify="required" placeholder="请输入姓名" autocomplete="off"
					class="layui-input">
			</div>
		</div>

		<div class="layui-form-item layui-inline">
			<label class="layui-form-label">生日</label>
			<div class="layui-input-block">
				<input type="text" name="birthday" id="birthday"
				value='<fmt:formatDate value="${stu.birthday}" pattern="yyyy-MM-dd HH:mm:ss"/>'  autocomplete="off" class="layui-input">
			</div>
		</div>

		<div class="layui-form-item layui-inline">
			<label class="layui-form-label">电话</label>
			<div class="layui-input-block">
				<input type="text" name="phone" value="${stu.phone}"
					placeholder="请输入电话" autocomplete="off" class="layui-input">
			</div>
		</div>

		<div class="layui-form-item layui-inline">
			<label class="layui-form-label">班级</label>
			<div class="layui-input-block">
				<select lay-verify="required" name="classId" id="cla"
					value="${stu.classId}">
					<a:forEach items="${cls}" var="b">
						<option value="${b.id}"
							<a:if test="${stu.classId==b.id}">selected</a:if>>${b.className}</option>
					</a:forEach>
				</select>
			</div>
		</div>

		<div class="layui-form-item layui-inline">
			<label class="layui-form-label">qq</label>
			<div class="layui-input-block">
				<input type="text" name="qq" value="${stu.qq}" placeholder="请输入qq号码"
					autocomplete="off" class="layui-input">
			</div>
		</div>

		<div class="layui-form-item layui-inline">
			<label class="layui-form-label">性别</label>
			<div class="layui-input-block">
				<select lay-verify="required" name="gender" id="gender">
				</select>
			</div>
		</div>


		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>


	<script src="static/layui/layui.js"></script>
	<script>
		layui.use([ 'table', 'form', 'laydate' ], function() {
			var table = layui.table;
			var form = layui.form;
			var $ = layui.$;
			var laydate = layui.laydate;

			//监听submit提交
			form.on('submit(formDemo)', function(data) {
				var studentId = $("input[name='studentId']").val();
				var url = "";
				if (studentId) {
					url = "editStu";
				} else {
					url = "addStu";
				}

				$.ajax({
					url : url,
					type : 'post',
					data : data.field,
					success : function(res) {
						if (res.code == 0) {
							layer.msg(res.msg, {
								icon : 6,
								time : 1000
							}, function() {
								var index = parent.layer
										.getFrameIndex(window.name); //先得到当前iframe层的索引

								parent.layer.close(index); //再执行关闭
								//刷新数据表格
								parent.layui.table.reload('idTest');
							});
						} else {
							layer.msg(res.msg, {
								icon : 5,
								time : 1000
							}, function() {
								var index = parent.layer
										.getFrameIndex(window.name); //先得到当前iframe层的索引

								parent.layer.close(index); //再执行关闭
								//刷新数据表格
								parent.layui.table.reload('idTest');
							});
						}
					}
				});
				return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
			});

			//加载性别数据
			function loadgender() {
				var sel = '${stu.gender}';
				var unsel = '';
			    if (sel == "女") {
					sel = "女";
					unsel = "男"
				} else {
					sel = "男";
					unsel = "女";
				}
				$("#gender").append(
						'<option value="'+sel+'">' + sel + '</option>');
				$("#gender").append(
						'<option value="'+unsel+'">' + unsel + '</option>');
				//动态组织表单，重新渲染
				form.render();
			}
			//加载性别下拉框数据
			loadgender()

			//执行一个laydate实例
			laydate.render({
				elem : '#birthday'//指定元素
				,
				type : 'datetime'
			});

		});
	</script>


</body>
</html>